package main.components.renderers;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.*;
import java.io.IOException;
/**
 * Created by s_shmakov on 23.06.14.
 */

public class TreeTitulRenderer extends DefaultTreeCellRenderer {

    public TreeTitulRenderer() {}

    public Component getTreeCellRendererComponent(
            JTree tree,
            Object value,
            boolean sel,
            boolean expanded,
            boolean leaf,
            int row,
            boolean hasFocus) {

        super.getTreeCellRendererComponent(
                tree, value, sel,
                expanded, leaf, row,
                hasFocus);

        int idEnd = value.toString().indexOf("__") + 2;
        super.setText(value.toString().substring(idEnd, value.toString().length()));

        if (value.toString().equals("Титул")) {
            super.setText("sdghjkdfhgjkd");
        }

//        if (value.toString().equals("Primavera P6 Structure")) {
//            try {
//                Image iconRoot = ImageIO.read(getClass().getResource("images/prima.png"));
//                setIcon(new ImageIcon(iconRoot));
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//            //setToolTipText("This book is in the Tutorial series.");
//        }

//        if (leaf) {
//            try {
//                Image iconProject = ImageIO.read(getClass().getResource("images/project.gif"));
//                setIcon(new ImageIcon(iconProject));
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
        return this;
    }
}
